package ch13;

public class StopWatch 
{
	
	private long elapseTime;
	private long startTime;
	private boolean isRunning;
	
	public StopWatch()
	{
		reset();
	}
	
	public void start()
	{
		if(isRunning){
			return;
		}
		isRunning = true;
		startTime = System.currentTimeMillis();
	}
	
	public void stop()
	{
		if(!isRunning){
			return;
		}
		long endTime = System.currentTimeMillis();
		elapseTime = elapseTime + endTime - startTime;
	}
	
	public long getElapseTime()
	{
		if(isRunning){
			long endTime = System.currentTimeMillis();
			return elapseTime + endTime - startTime;
		} else {
			return elapseTime;
		}
		
	}

	private void reset() {
		elapseTime = 0;
		isRunning = false;		
	}

}
